


import 'package:erp/Entity/Product.dart';
import 'package:erp/Store/ProductStore.dart';
import 'package:erp/UI/Components/CustomizedScaffold.dart';
import 'package:erp/UI/Components/HeroLogo.dart';
import 'package:erp/UI/Components/KeyValueView.dart';
import 'package:erp/UI/Components/ListDividerGenerator.dart';
import 'package:erp/UI/Components/LogoScaffold.dart';
import 'package:erp/UI/Components/MessageDialog.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/ProductManagementPages/AddProductPage.dart';
import 'package:erp/UI/Pages/BasicInformationManagementPages/ProductManagementPages/ProductViewer.dart';
import 'package:flutter/material.dart';

class ProductInfoManagement extends StatefulWidget {
  bool isSelectionMode;
  String title;

  ProductInfoManagement({this.isSelectionMode = false, this.title = "تاۋار ئۇچۇرىنى باشقۇرۇش"});

  @override
  State<StatefulWidget> createState() {
    return ProductInfoManagementState(_Param(
      title: title,
      isSelectionMode: isSelectionMode
    ));
  }
}

class _Param {
  String title;
  bool isSelectionMode;

  _Param({this.title, this.isSelectionMode});
}

class ProductInfoManagementState extends State<ProductInfoManagement> {
  _Param parameter;
  ProductInfoManagementState(this.parameter);

  @override
  Widget build(BuildContext context) {
    return CustomizedScaffold(
      expandedHeight: 260.0,
      appbarContent: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          HeroLogo(
            assetsLogoName: "assets/pictures/boxes.png",
            heroName: "ProductInfoManagementPageLogo",
          ),
          Container(
            child: KeyValueView({
              "بارلىق تاۋار سانى:": "${ProductStore.products.length} دانە",
//              "Age": 24,
            },
              margin: EdgeInsets.symmetric(horizontal: 10.0),
              width: 230.0,
              textColor: Colors.white,
            ),
          )
        ],
      ),
      title: parameter.title,
      contentDelegate: SliverChildListDelegate([
        Padding(
          padding: EdgeInsets.only(top: 10.0),
          child: ProductViewer(isSelectionMode: parameter.isSelectionMode,),
        )
      ]),
      floatingActionButton: FloatingActionButton(
        heroTag: "FloatingActionButton",
          onPressed: () async {
            var product = Product(
              imgurl: "",
              id: -1,
              code: "",
              unit: "",
              addtionalProperties: [],
              barCode: "",
              createdAt: "",
              inPrice: 0.0,
              isremove: 0,
              maxCount: 0.0,
              comment: "",
              minCount: 0.0,
              nameUg: "",
              nameZh: "",
              shop: -1,
              sellPrice: 0.0,
              typeId: 0,
              typeName: "",
              updatedAt: ""
            );

            Navigator.of(context).push(MaterialPageRoute(builder: (context) {
              return AddProductPage(
                product,
                OperationMode.ADD,
                heroName: "FloatingActionButton",
              );
            }));
          },
          child: Icon(Icons.add),
        ),
      useSearchBar: true,
    );
  }
}